package com.example.Service;

import com.example.PO.Customer;

import java.util.ArrayList;
import java.util.List;

public class CustomerService {
    private List<Customer> customers = new ArrayList<>();

    public CustomerService() {
        // 初始化一些示例数据
        customers.add(new Customer(1, "张三", "13800138000", "北京市朝阳区"));
    }

    public List<Customer> getAllCustomers() {
        return customers;
    }

    public void addCustomer(Customer customer) {
        customers.add(customer);
    }

    public void updateCustomer(Customer customer) {
        for (Customer c : customers) {
            if (c.getId() == customer.getId()) {
                c.setName(customer.getName());
                c.setPhone(customer.getPhone());
                c.setAddress(customer.getAddress());
                break;
            }
        }
    }

    public void deleteCustomer(int id) {
        customers.removeIf(customer -> customer.getId() == id);
    }
}